package main

import (
	"context"
	"go-fast/app/api_http"
	"go-fast/global"
	"log"
	"os"
	"os/signal"
	"time"
)

func main() {
	// 初始化全局变量
	if err := global.InitGlobal("config.yaml"); err != nil {
		panic(err)
	}

	// new http服务
	srv := api_http.NewApiHttpServer()

	// 启动http 服务
	go func() {
		srv.Run()
	}()

	// 优雅Shutdown（或重启）服务
	quit := make(chan os.Signal)
	signal.Notify(quit, os.Interrupt) // syscall.SIGKILL
	<-quit
	global.Log.Info("Shutdown Server ...")
	global.Close()

	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()
	if err := srv.Shutdown(ctx); err != nil {
		log.Fatal("Server Shutdown:", err)
	}
	select {
	case <-ctx.Done():
	}
	log.Println("Server exiting")

}
